package com.utils.basejava.base;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Map;

/**
 * @author: zhaozongyi
 * @date: 2022-08-05 11:19
 */
public class MapTest {

    public static void main(String[] args) {
        Employ employ = new Employ("张三",1,200d);
        Employ employ1 = new Employ("张三1",11,2100d);
        Employ employ2 = new Employ("张三2",12,2200d);
        Employ employ3 = new Employ("张三3",13,2300d);
//        Map<String, Employ> maps = Maps.newLinkedHashMap();
        Map<String, Employ> maps = Maps.newHashMap();
        maps.put(employ.getName(), employ);
        maps.put(employ1.getName(), employ1);
        maps.put(employ1.getName(), employ2);
        maps.put(employ1.getName(), employ3);
        maps.forEach((key, value)-> System.out.println(key+","+value));
        employ1.setAge(222);// 对象更改，那么maps中存放的对象也会更改
        System.out.println("---");
        maps.put(employ1.getName(), employ1);
        maps.forEach((key, value)-> System.out.println(key+","+value));
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
class Employ {
    String name;
    Integer age;
    Double salary;
}